layui.define([], function (e) {
    var $ = layui.$;
    var fmat = {
        newObj: {},
        //   时间格式化 YY-MM-DD HH:MM:SS
        TimeFormat: function () {            
        var year = new Date().getFullYear(),
            month = new Date().getMonth() + 1,
            day = new Date().getDate(),
            h = new Date().getHours(),
            m = new Date().getMinutes(),
            s = new Date().getSeconds()
        var today = year + '-' + (month < 10 ? '0' + month : month) + '-' + (day < 10 ? '0' + day : day) +
                     ' ' + (h < 10 ? '0' + h : h) + ':' + (m < 10 ? '0' + m : m) + ':' + (s < 10 ? '0' + s : s);
        return today;
        },
        //生成随机数
        randomWord: function(randomFlag, min, max){
            var str = "",
                range = min,
                arr = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'];
         
            // 随机产生
            if(randomFlag){
                range = Math.round(Math.random() * (max-min)) + min;
            }
            for(var i=0; i<range; i++){ //限定长度
                pos = Math.round(Math.random() * (arr.length-1));
                str += arr[pos];
            }
            return str;
        },
        //odata数据格式
        oDataTran: function(obj){
            var arr = [];
            Object.keys(obj).forEach(function(key){
                if(obj[key] !== ""){
                    arr.push(key + " eq " + obj[key]); 
                }
            });
            var join = arr.join(" and ");
            return join;
        },
        // 过滤未修改值的属性
        isObjEqual: function (o1, o2) {
            var props1 = Object.getOwnPropertyNames(o1);
            var props2 = Object.getOwnPropertyNames(o2);
            if (props1.length != props2.length) {
                return false;
            }
            for (var i = 0, max = props1.length; i < max; i++) {
                var propName = props1[i];
                if (o1[propName] !== o2[propName]) {
                    fmat.newObj[propName] = o2[propName];
                }
            }
            return fmat.newObj;
        },
        // 去掉空值的属性
        isObjBlank: function (o) {
            var props = Object.getOwnPropertyNames(o);
            for (var i = 0, max = props.length; i < max; i++) {
                var propName = props[i];
                if (o[propName] === "") {
                    delete o[propName];
                }
            }
            return o;
        },
        // 时间格式化
        timeStampFormat: function(tstr){
            var date = new Date(parseInt(tstr));
                y = date.getFullYear(),
                m = date.getMonth() + 1,
                d = date.getDate();
            return y + "-" + (m < 10 ? "0" + m : m) + "-" + (d < 10 ? "0" + d : d) + " " + date.toTimeString().substr(0, 8);
        }
    };
    e('format', {
        fm: fmat
    })

});